<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row :span="24">
        <el-col :span="12" style="width: 200px">
          <el-form-item label="归属部门" prop="deptId">
            <treeselect v-model="deptTree" :options="deptOptions" :show-count="true" placeholder="请选择班级" />
          </el-form-item>
        </el-col>
        <el-col :span="12" style="margin-top: 33px">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['zc:grade:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['zc:grade:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['zc:grade:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['zc:grade:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="test1"
        >测试</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="gradeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="学号" align="center" prop="userNumber" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="班级" align="center" prop="deptName" />
      <el-table-column label="综测成绩" align="center" prop="gradeSum" />
<!--      <el-table-column label="状态" align="center" prop="gradeOrganization" />-->
<!--      <el-table-column label="身体素质" align="center" prop="gradePhysical" />-->
<!--      <el-table-column label="社会实践" align="center" prop="gradePractice" />-->
<!--      <el-table-column label="科学研究" align="center" prop="gradeScience" />-->
<!--      <el-table-column label="院系加分" align="center" prop="gradeDepartment" />-->
<!--      <el-table-column label="文体活动" align="center" prop="gradeActivities" />-->
<!--      <el-table-column label="专业扩展" align="center" prop="gradeProfession" />-->
<!--      <el-table-column label="职业技能" align="center" prop="gradeSkill" />-->
<!--      <el-table-column label="其他加分" align="center" prop="gradeOther" />-->
      <el-table-column label="综测状态(-1未审核，0已审核，1,2,3上级审核)" align="center" prop="gradeStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.zc_grade_status" :value="scope.row.gradeStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['zc:grade:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['zc:grade:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

<!--    <pagination-->
<!--      v-show="total>0"-->
<!--      :total="total"-->
<!--      :page.sync="queryParams.pageNum"-->
<!--      :limit.sync="queryParams.pageSize"-->
<!--      @pagination="getList"-->
<!--    />-->

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="思想政治" prop="gradePolitics">
          <el-input v-model="form.gradePolitics" placeholder="请输入思想政治" />
        </el-form-item>
        <el-form-item label="个人品德" prop="gradeMorality">
          <el-input v-model="form.gradeMorality" placeholder="请输入个人品德" />
        </el-form-item>
        <el-form-item label="学习态度" prop="gradeAttitude">
          <el-input v-model="form.gradeAttitude" placeholder="请输入学习态度" />
        </el-form-item>
        <el-form-item label="组织纪律" prop="gradeOrganization">
          <el-input v-model="form.gradeOrganization" placeholder="请输入组织纪律" />
        </el-form-item>
        <el-form-item label="身体素质" prop="gradePhysical">
          <el-input v-model="form.gradePhysical" placeholder="请输入身体素质" />
        </el-form-item>
        <el-form-item label="社会实践" prop="gradePractice">
          <el-input v-model="form.gradePractice" placeholder="请输入社会实践" />
        </el-form-item>
        <el-form-item label="科学研究" prop="gradeScience">
          <el-input v-model="form.gradeScience" placeholder="请输入科学研究" />
        </el-form-item>
        <el-form-item label="院系加分" prop="gradeDepartment">
          <el-input v-model="form.gradeDepartment" placeholder="请输入院系加分" />
        </el-form-item>
        <el-form-item label="文体活动" prop="gradeActivities">
          <el-input v-model="form.gradeActivities" placeholder="请输入文体活动" />
        </el-form-item>
        <el-form-item label="专业扩展" prop="gradeProfession">
          <el-input v-model="form.gradeProfession" placeholder="请输入专业扩展" />
        </el-form-item>
        <el-form-item label="职业技能" prop="gradeSkill">
          <el-input v-model="form.gradeSkill" placeholder="请输入职业技能" />
        </el-form-item>
        <el-form-item label="其他加分" prop="gradeOther">
          <el-input v-model="form.gradeOther" placeholder="请输入其他加分" />
        </el-form-item>
        <el-form-item label="备注信息" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listGrade, getGrade, delGrade, addGrade, updateGrade } from "@/api/zc/grade";
import { getZcUserGradeList,test,getUserGradeListByDeptId,getUserGradeListAll } from "@/api/zc/userGrade";
import { deptTreeSelect } from "@/api/system/user";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";


export default {
  dicts: ['zc_grade_status'],
  name: "Grade",
  components: { Treeselect },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      gradeList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        gradePolitics: null,
        gradeMorality: null,
        gradeAttitude: null,
        gradeOrganization: null,
        gradePhysical: null,
        gradePractice: null,
        gradeScience: null,
        gradeDepartment: null,
        gradeActivities: null,
        gradeProfession: null,
        gradeSkill: null,
        gradeOther: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        gradePolitics: [
          { required: true, message: "思想政治不能为空", trigger: "blur" }
        ],
        gradeMorality: [
          { required: true, message: "个人品德不能为空", trigger: "blur" }
        ],
        gradeAttitude: [
          { required: true, message: "学习态度不能为空", trigger: "blur" }
        ],
        gradeOrganization: [
          { required: true, message: "组织纪律不能为空", trigger: "blur" }
        ],
        gradePhysical: [
          { required: true, message: "身体素质不能为空", trigger: "blur" }
        ],
        gradePractice: [
          { required: true, message: "社会实践不能为空", trigger: "blur" }
        ],
        gradeScience: [
          { required: true, message: "科学研究不能为空", trigger: "blur" }
        ],
        gradeDepartment: [
          { required: true, message: "院系加分不能为空", trigger: "blur" }
        ],
        gradeActivities: [
          { required: true, message: "文体活动不能为空", trigger: "blur" }
        ],
        gradeProfession: [
          { required: true, message: "专业扩展不能为空", trigger: "blur" }
        ],
        gradeSkill: [
          { required: true, message: "职业技能不能为空", trigger: "blur" }
        ],
        gradeOther: [
          { required: true, message: "其他加分不能为空", trigger: "blur" }
        ],
        status: [
          { required: true, message: "综测状态(-1未审核，0已审核，1,2,3上级审核)不能为空", trigger: "change" }
        ],
      },
      deptOptions:[],
      deptTree:'',
    };
  },
  created() {
    this.getDeptTree();
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;//this.queryParams
      getZcUserGradeList().then(response => {
        this.gradeList = response.data;
        // this.total = response.total;
        this.loading = false;
      });
      console.log(this.gradeList)
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        gradeId: null,
        gradePolitics: null,
        gradeMorality: null,
        gradeAttitude: null,
        gradeOrganization: null,
        gradePhysical: null,
        gradePractice: null,
        gradeScience: null,
        gradeDepartment: null,
        gradeActivities: null,
        gradeProfession: null,
        gradeSkill: null,
        gradeOther: null,
        status: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      // this.getList();
      // console.log('this.deptTree');
      // console.log(this.deptTree);
      getUserGradeListByDeptId(this.deptTree).then(response =>{
        this.gradeList = response.data;
      })
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.gradeId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const gradeId = row.gradeId || this.ids
      getGrade(gradeId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.gradeId != null) {
            updateGrade(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGrade(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const gradeIds = row.gradeId || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + gradeIds + '"的数据项？').then(function() {
        return delGrade(gradeIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('zc/grade/export', {
        ...this.queryParams
      }, `grade_${new Date().getTime()}.xlsx`)
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
        this.deptTree = response.data.label;
      });
    },
    test1(){
      getUserGradeListAll().then(response => {
        console.log('Test : response.data');
        console.log(response.data);
        this.gradeList=response.data;
      });
    }
  }
};
</script>
